/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events;

import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.GUIDStorage;

import org.json.simple.JSONObject;

/**
 * @author Massimo Canonaco
 *
 */
public class EndMatchEvent implements GenericEvent 
{
	private String winnerName;
	
	private String loserName;
	
	/** */
	static public final float GUID = GUIDStorage.END_MATCH_EVENT;
	
	public EndMatchEvent() {
		winnerName = "";
		loserName  = "";
	}
	/** */
	public EndMatchEvent(final String winner, final String loser)
	{
		winnerName = winner;
		loserName = loser;
	}
	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getGUID()
	 */
	@Override
	public float getGUID() 
	{
		return GUID;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent#getName()
	 */
	@Override
	public String getName() 
	{
		return null;
	}
	
	/**
	 * @return the winnerName
	 */
	public String getWinnerName() 
	{
		return winnerName;
	}
	/**
	 * @return the loserName
	 */
	public String getLoserName() 
	{
		return loserName;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public JSONObject getAsJSONObject() 
	{
		JSONObject object = new JSONObject();
		object.put(GLOBAL_GUID_KEY, GUID);
		object.put(WINNER_KEY, winnerName);
		object.put(LOSER_KEY, loserName);
		return object;
	}
	@Override
	public void setFromJSONOnbject(JSONObject object) 
	{
		winnerName = (String) object.get(WINNER_KEY);
		loserName = (String) object.get(LOSER_KEY);
	}

	static private final String WINNER_KEY = "thewinneris";
	static private final String LOSER_KEY = "theloseris";
}
